#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
const int N = 2e5 + 10;
long long dp[N];
int n;
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        long long x = 0;
        cin >> x;
        dp[i] = max(dp[i - 1] + x, x);
    }
    long long ret = -1e5;
    for (int i = 1; i <= n; i++)
    {
        ret = max(ret, dp[i]);
    }
    cout << ret;
    return 0;
}